<html lang="zh-cn">
<head>
{% include "tdm_include_head_template.html" %}
<script type="text/javascript" src="/static/js/bootstrap-multiselect.js"></script>
<script type="text/javascript">
function show_station(station) {
  sta_list = station.split(',')
  for (sta in sta_list) {
    if (sta_list[sta]) {
      document.write(sta_list[sta]+"<br/>");
    }
  }
}
$(document).ready(function() {
  $("select#new_station").multiselect({
    buttonWidth: '150px',
    includeSelectAllOption: true,
    maxHeight: 150
  });
});
</script>
</head>

<body class=" theme-blue">
{% include "tdm_include_navbar_template.html" %}

<div class="container">
  <br/>
  {% include "tdm_include_error_template.html" %}

  {% include "tdm_include_admin_page_template.html" %}

  <div class="form-context">
    <form id="tdm_user_form" action="/tdm/admin/user/" method="post">
    <table class="table table-hover">
      <tr>
        <th>用户</th>
        <th>邮箱</th>
        <th>电话</th>
        <th>登陆时间</th>
        <th>权限</th>
        <th>市地</th>
        <td><button type="submit" name="op" value="user_del" class="btn btn-primary">删除</button></td>
      </tr>
      {% for tdm_user in user_list %}
      <tr>
        <td>{{tdm_user.name}}</td>
        <td>{{tdm_user.email}}</td>
        <td>{{tdm_user.phone}}</td>
        <td><script>var d = new Date("{{tdm_user.lastlogin_tm.isoformat}}"); document.write(d.toLocaleString());</script></td>
        <td>{{tdm_user.grant}}</td>
        <td>{% for city in tdm_user.station %}{{city.name}}, {% endfor %}</td>
        <td><label><input type="checkbox" name="del_user" value="{{tdm_user.name}}"></label></td>
      </tr>
      {% endfor %}
      <tr>
        <td><input type="text" class="form-control" name="new_user" placeholder="用户名"></td>
        <td><input type="email" class="form-control" name="new_email" placeholder="邮箱"></td>
        <td><input type="phone" class="form-control" name="new_phone" placeholder="电话"></td>
        <td><input type="password" class="form-control" name="new_password" placeholder="密码"></td>
        <td><select name="new_role" class="form-control">
          <option value='view'>普通用户</option>
          <option value='admin'>管理员</option>
        </select></td>
        <td><select id="new_station" name="new_station" class="form-control" multiple="multiple">
        {% for city in city_all %}
          <option value="{{city.zipcode}}">{{city.name}}</option>
        {% endfor %}
        </select></td>
        <td><button type="submit" name="op" value="user_add" class="btn btn-primary">添加</button></td>
      </tr>
    </table>
    </form>
  </div>
  {% include "tdm_include_footer_template.html" %}
</div>
</body>
</html>